local s4__zhongyi = fk.CreateSkill {
  name = "s4__zhongyi",
  tags = { Skill.Limited },
}

Fk:loadTranslationTable {
  ["s4__zhongyi"] = "忠义",
  [":s4__zhongyi"] = "出牌阶段，若你没有“义”，你可以将任意张红色牌置为“义”。当己方角色使用【杀】对对方角色造成伤害时，你移去一张“义”，令此伤害+1。",

  ["#s4__zhongyi"] = "忠义：将任意张红色牌置于武将牌上，友方使用【杀】造成伤害时移去一张，此伤害+1",
}

s4__zhongyi:addEffect("active", {
  anim_type = "offensive",
  target_num = 0,
  min_card_num = 1,
  prompt = "#s4__zhongyi",
  derived_piles = s4__zhongyi.name,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  card_filter = function(self, player, to_select, selected)
    return Fk:getCardById(to_select).color == Card.Red and #selected == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    player:addToPile(s4__zhongyi.name, effect.cards, true, s4__zhongyi.name, player)
  end,
})

s4__zhongyi:addEffect(fk.DamageCaused, {
  anim_type = "offensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target and #player:getPile(s4__zhongyi.name) > 0 and
        data.card and data.card.trueName == "slash" and
        target:isFriend(player)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("s4__zhongyi")
    room:notifySkillInvoked(player, "s4__zhongyi", "offensive")
    data:changeDamage(1)
  end,
})

s4__zhongyi:addEffect(fk.RoundEnd, {
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return #player:getPile("s4__zhongyi") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:moveCardTo(table.random(player:getPile(s4__zhongyi.name)), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile,
      "s4__zhongyi", nil, true, player.id)
  end,
})

return s4__zhongyi
